﻿<!--popular downloads starts-->
<div id="popular-downloads">  
    <table class="table table-striped table-bordered table-condensed">
       <tr> 
            <td colspan="3">
                <div class="text-center">
                    <h4>
                        ::: Most Popular Downloads :::
                        <br />
                        <small>Downloads for last week</small>
                    </h4> 
                </div>
            </td>
        </tr>
        <tbody data-bind="foreach: PopularDownloads">
            <tr>
                <td class="counts" data-bind="text: pdicn"></td>
                <td class="text-muted"><a data-bind="text: pdn, click: $parent.redirectProductPage"></a></td>
                <td class="counts" data-bind="text: pdc"></td>
            </tr>
        </tbody>
    </table>
</div>
<script>
    var DummyPopularDownloads = [
                            {
                                "pdicn": 1,
                                "pdn": "Avast Free Antivirus 2015",
                                "pdc": 1155403,
                            },
                            {
                                "pdicn": 2,
                                "pdn": "KM Player",
                                "pdc": 22000,
                            },
                            {
                                "pdicn": 1,
                                "pdn": "Avast Free Antivirus 2015",
                                "pdc": 1155403,
                            },
                            {
                                "pdicn": 2,
                                "pdn": "KM Player",
                                "pdc": 22000,
                            },
                            {
                                "pdicn": 1,
                                "pdn": "Avast Free Antivirus 2015",
                                "pdc": 1155403,
                            },
                            {
                                "pdicn": 2,
                                "pdn": "KM Player",
                                "pdc": 22000,
                            },
                            {
                                "pdicn": 1,
                                "pdn": "Avast Free Antivirus 2015",
                                "pdc": 1155403,
                            },
                            {
                                "pdicn": 2,
                                "pdn": "KM Player",
                                "pdc": 22000,
                            }
                        ];

    var PopularDownloadsViewModel = function () {
        var self = this;

        self.redirectProductPage = function (productselected) {
            alert("Product selected name: "+productselected.pdn);
            //if (confirm("Are you sure you want to delete this profile?")) {
            //    self.PopularDownloads.remove(profile);
            //}
            //if (DummyProfile.length <= 0) {
            //    alert("no more records exist");
            //}
        };

        var refresh = function () {
            if (DummyPopularDownloads.length > 0) {
                self.PopularDownloads(DummyPopularDownloads);
            }
            else {
                alert("no more records exist");
            }
        };

        // Public data properties
        self.PopularDownloads = ko.observableArray([]);
        refresh();
    };    
    ko.applyBindings(new PopularDownloadsViewModel(), document.getElementById("popular-downloads"));
</script>
<!--popular downloads ends-->